
import time
from Common.basepage import BasePage
from PageObjects.Main_page import MainPage
from PageObjects.Player_page import PlayerPage
from Common.basepage import BasePage
from Common.handle_log import do_log
from PageLocators.MainPage_locator import MainPageLocator as loc
from Common.connect_to_device import *

do_basepage = BasePage(device="d_one")
do_mainpage = MainPage(device="d_one")
do_playpage = PlayerPage(device="d_one")



class SeatRhythm:
    """
    座椅律动
    座椅律动：封神第一部 00:03:28~00:04:50 座椅跟随声音轻微震动
    5D指令:onSeatShake: ts = 00:03:28, action = 5, strength = 3
    前后排不提前下发
    """
    def __init__(self):
        self.command=r'onSeatShake: ts = 00:03:28, action = 5, strength = 3'
        self.time_5D=r'GetCurrentTimeStamp timestamp : 2081\d{2}'
        self.time_front = r'GetCurrentTimeStamp timestamp : 203\d{3}'
        self.seek_all=r"onGetCurrentTimeStamp seek : 00:0[0-3]:\d{2} -> 00:03:\d{2}"
    def seek_back(self):
        events_sequential_list = [
                                  {"event_name": "00seek下发追溯检测:首次seek操作",
                                   "event_pattern": 'onGetCurrentTimeStamp seek : 00:'},
                                  {"event_name": "00seek下发追溯检测:5D律动灯光追溯1",
                                   "event_pattern": r'onShowColor ts: 00:00:00|onSeatShake: ts = 00:00:00'},
                                  {"event_name": "00seek下发追溯检测:5D律动灯光追溯2",
                                   "event_pattern": r'onShowColor ts: 00:00:00|onSeatShake: ts = 00:00:00'},
                                {"event_name": "00seek下发追溯检测:resume",
                                 "event_pattern": r'resume'},
                                  {"event_name": "00seek下发追溯检测:追溯seek操作",
                                   "event_pattern": 'onGetCurrentTimeStamp seek : '}
                                  ]
        return events_sequential_list, 4

    def start_action(self):
        """座椅律动下发时操作：打开封神第一部 seek到3:20持续播放15s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        do_playpage.seek_to_target("00:03:20")
        time.sleep(15)
    def start_action_not(self):
        """座椅律动下发前操作：打开封神第一部 seek到3:10持续播放10s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        do_playpage.seek_to_target("00:03:10")
        time.sleep(10)
    def front_exist_not(self):
        """5D指令下发前顺序判定条件：seek,自然播放,OnSeat recoverShake"""
        events_sequential_list = [{"event_name": "01顺序检索指令下发检测:跳转进度条",
                                   "event_pattern": self.seek_all},
                                  {"event_name": "01顺序检索指令下发检测:自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "01顺序检索指令下发检测:座椅状态恢复1",
                                   "event_pattern": r':OnSeat recoverShake'},
                                  {"event_name": "01顺序检索指令下发检测:座椅状态恢复2",
                                   "event_pattern": r'OnSeat setSeat\w* success'}
                                  ]
        return events_sequential_list,2
    def front_exist(self):
        """5D指令下发时顺序判定条件：seek,自然播放,5D指令下发,OnSeat recoverShake"""
        events_sequential_list = [{"event_name": "01顺序检索指令下发检测:跳转进度条",
                                   "event_pattern": self.seek_all},
                                  {"event_name": "01顺序检索指令下发检测:自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "01顺序检索指令下发检测:5D指令下发",
                                   "event_pattern": self.command},
                                  {"event_name": "01顺序检索指令下发检测:座椅状态恢复1",
                                   "event_pattern": r'OnSeat recoverShake'},
                                  {"event_name": "01顺序检测:座椅状态恢复2",
                                   "event_pattern": r'OnSeat setSeat\w* success'}
                                  ]
        return events_sequential_list,4
    def back_exist_5DSDK(self,expect=False):
        """座椅律动时区间判定条件：在OnSeat setSeatVentilationLevel success 到日志结束之后有无 自然播放GetCurrentTimeStamp下发"""
        events_exist_list = [
            {"start_pattern": r'OnSeat setSeat\w* success',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp|ts = 00:00:00',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list

    def back_exist_time(self, expect=False):
        """座椅律动时区间判定条件：在全部日志中有无5D时间下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": self.time_5D,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list

    def back_exist_5D(self, expect=False):
        """座椅律动时区间判定条件：在全部日志中有无 5D指令下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern":self.command,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list
class SeatAtomizationVibration:
    """
    座椅原子化振动
    座椅原子化振动：封神第一部 00:06:14   00:06:17
    5D指令:onSeatShake: ts = 00:06:14, action = 5, strength = 1002
    前后排不提前下发
    """
    def __init__(self):
        self.command=r'onSeatShake: ts = 00:06:14, action = 5, strength = 1002'
        self.time_5D=r'GetCurrentTimeStamp timestamp : 3741\d{2}'
        self.seek_all=r"onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:06:\d{2}"
    def start_action_not(self):
        """座椅原子化振动下发前操作：打开封神第一部 seek到06:08持续播放5s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        do_playpage.seek_to_target("00:06:08")
        time.sleep(5)
    def start_action(self):
        """座椅原子化振动下发前操作：打开封神第一部 seek到06:08持续播放5s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        do_playpage.seek_to_target("00:06:08")
        time.sleep(5)
    def  front_exist_not(self):
        """座椅原子化振动下发前顺序判定条件：seek,自然播放,pause,OnSeat recoverShake"""
        events_sequential_list = [{"event_name": "01顺序检索指令下发检测:跳转进度条",
                                   "event_pattern": self.seek_all},
                                  {"event_name": "01顺序检索指令下发检测:自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "01顺序检索指令下发检测:座椅状态恢复1",
                                   "event_pattern": r':OnSeat recoverShake'},
                                  {"event_name": "01顺序检索指令下发检测:座椅状态恢复2",
                                   "event_pattern": r'OnSeat setSeat\w* success'}
                                  ]
        return events_sequential_list,3

    def back_exist_5DSDK(self, expect=False):
        """座椅律动时区间判定条件：在OnSeat setSeatVentilationLevel success 到日志结束之后有无 自然播放GetCurrentTimeStamp下发"""
        events_exist_list = [
            {"start_pattern": r'OnSeat setSeat\w* success',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp|ts = 00:00:00',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list

    def back_exist_time(self, expect=False):
        """座椅律动时区间判定条件：在全部日志中有无5D时间下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": self.time_5D,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list

    def back_exist_5D(self, expect=False):
        """座椅律动时区间判定条件：在全部日志中有无 5D指令下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": self.command,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list
class SeatMassage:
    """
    座椅按摩
    座椅按摩：封神第一部  00:58:15~00:58:23
    5D指令:onSeatShake: ts = 00:58:15, action = 13, strength = 3
    """
    def __init__(self):
        self.command=r'onSeatShake: ts = 00:06:14, action = 5, strength = 1002'
        self.time_5D=r'GetCurrentTimeStamp timestamp : 3741\d{2}'
        self.seek_all=r"onGetCurrentTimeStamp seek : 00:d{2}:\d{2} -> 00:06:\d{2}"
    def start_action(self):
        """座椅按摩时操作：打开封神第一部 seek到58:10持续播放15s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        do_playpage.seek_to_target("00:58:08")
        time.sleep(15)
    def start_action_not(self):
        """座椅按摩时操作：打开封神第一部 seek到58:00持续播放8s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        do_playpage.seek_to_target("00:58:00")
        time.sleep(8)
    def front_exist_not(self):
        """座椅按摩前顺序判定条件：seek,自然播放，OnSeat recoverShake"""
        events_sequential_list = [{"event_name": "跳转进度条到 00:57:50 ",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:\d{2}:\d{2}'},
                                  {"event_name": "开始自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "座椅状态恢复1",
                                   "event_pattern": r':OnSeat recoverShake'},
                                  {"event_name": "座椅状态恢复2",
                                   "event_pattern": r'OnSeat setSeat\w* success'}]
        return events_sequential_list,2
    def front_exist(self):
        """座椅按摩时顺序判定条件：seek,自然播放，5D指令,OnSeat recoverShake"""
        events_sequential_list =[{"event_name": "跳转进度条到 00:58:10",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:58:\d{2}'},
                                 {"event_name": "开始自然播放",
                                  "event_pattern": r'GetCurrentTimeStamp timestamp : \d{7}'},
                                  {"event_name": "座椅按摩开启",
                                   "event_pattern": r'onSeatShake: ts = 00:58:15, action = 13, strength = 3'},
                                  {"event_name": "座椅状态恢复1", "event_pattern": r':OnSeat recoverShake'},
                                  {"event_name": "座椅状态恢复2",
                                   "event_pattern": r'OnSeat setSeat\w* success'}
                                  ]
        return events_sequential_list,3
    def back_exist_5DSDK(self,expect=False):
        """座椅按摩时区间判定条件：在OnSeat setSeatVentilationLevel success 到日志结束之后有无 5D-SDK下发"""
        events_exist_list = [
            {"start_pattern": r'OnSeat setSeat\w* success',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp|ts = 00:00:00',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list

    def back_exist_time(self, expect=False):
        """座椅按摩时区间判定条件：在全部日志中有无 GetCurrentTimeStamp timestamp : 3495\d{3}下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp : 3495\d{3}',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list
    def back_exist_5D(self, expect=False):
        """座椅按摩时区间判定条件：在全部日志中有无 onSeatShake: ts = 00:58:15, action = 13, strength =3 下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": r'onSeatShake: ts = 00:58:15, action = 13, strength = 3',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect":expect}
        ]
        return events_exist_list
class SeatHeating:
    """
    座椅加热
    座椅加热：座椅加热 封神第一部 00:10:34~00:11:18
    5D指令后排:onSeatShake: ts = 00:10:24, action = 7, strength = 3
    5D指令前排:onSeatShake: ts = 00:10:34, action = 7, strength = 3
    后排提前10S下发
    """
    def start_action(self):
        """座椅加热下发时操作：打开封神第一部 seek到10:20/28持续播放10s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        if device_type == "A1Back":
            do_playpage.seek_to_target("00:10:20")
        else:
            do_playpage.seek_to_target("00:10:28")
        time.sleep(10)
    def start_action_not(self):
        """座椅加热下发前操作：打开封神第一部 seek到10:12持续播放10s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        if device_type == "A1Back":
            do_playpage.seek_to_target("00:10:12")
        else:
            do_playpage.seek_to_target("00:10:20")
        time.sleep(10)
    def front_exist_not(self):
        """座椅加热前顺序判定条件：seek,自然播放，OnSeat recoverShake"""
        events_sequential_list = [{"event_name": "跳转进度条到 00:10:20",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:10:\d{2}'},
                                  {"event_name": "开始自然播放10s",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "座椅状态恢复1",
                                   "event_pattern": r':OnSeat recoverShake'},
                                  {"event_name": "座椅状态恢复2",
                                   "event_pattern": r'OnSeat setSeat\w* success'}]
        return events_sequential_list
    def front_exist(self):
        """座椅加热时顺序判定条件：seek,自然播放，5D指令,OnSeat recoverShake"""
        if device_type == "A1Back":
            ins_5D=r'onSeatShake: ts = 00:10:24, action = 7, strength = 3'
        else:
            ins_5D=r'onSeatShake: ts = 00:10:34, action = 7, strength = 3'
        events_sequential_list = [{"event_name": "跳转进度条到 00:10:28",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:10:\d{2}'},
                                  {"event_name": "开始自然播放10s",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "座椅律动开启，强度3",
                                   "event_pattern": ins_5D},
                                  {"event_name": "座椅状态恢复1",
                                   "event_pattern": r':OnSeat recoverShake'},
                                  {"event_name": "座椅状态恢复2",
                                   "event_pattern": r'OnSeat setSeat\w* success'}]
        return events_sequential_list
    def back_exist_5DSDK(self,expect=False):
        """座椅加热区间判定条件：在OnSeat setSeatVentilationLevel success 到日志结束之后有无 5D-SDK下发"""
        events_exist_list = [
            {"start_pattern": r'OnSeat setSeat\w* success',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp|ts = 00:00:00',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list

    def back_exist_time(self, expect=False):

        """座椅加热区间判定条件：在全部日志中有无 GetCurrentTimeStamp timestamp : 前排634后排624\d{3}下发"""
        if device_type == "A1Back":
            time_5D=r'GetCurrentTimeStamp timestamp : 624\d{3}'
        else:
            time_5D=r'GetCurrentTimeStamp timestamp : 634\d{3}'
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern":time_5D,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list
    def back_exist_5D_recover(self,expect=False):
        """座椅加热区间判定条件：在OnSeat setSeatVentilationLevel success 到日志结束之后有无 5D-SDK下发"""
        if device_type == "A1Back":
            ins_5D=r'onSeatShake: ts = 00:10:24, action = 7, strength = 3'
        else:
            ins_5D=r'onSeatShake: ts = 00:10:34, action = 7, strength = 3'
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern":ins_5D,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list
class SeatVentilation:
    """
    座椅通风
    "座椅通风：封神第一部 00:03:03~00:14:12"
    5D指令:onSeatShake: ts = 00:03:03, action = 11, strength = 3
    前后排不提前下发
    """
    def start_action(self):
        """座椅通风时操作：打开封神第一部 seek到2:55持续播放15s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        do_playpage.seek_to_target("00:02:55")
        time.sleep(15)
    def start_action_not(self):
        """座椅通风前操作：打开封神第一部 seek到2:45持续播放10s"""
        do_mainpage.enter_film("封神第一部：朝歌风云")
        time.sleep(8)
        do_playpage.seek_to_target("00:02:45")
        time.sleep(10)
    def front_exist_not(self):
        """座椅通风前顺序判定条件：seek,自然播放，OnSeat recoverShake"""
        events_sequential_list = [{"event_name": "跳转进度条到 00:02:45",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:\d{2}:\d{2}'},
                                  {"event_name": "自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "座椅状态恢复1",
                                   "event_pattern": r':OnSeat recoverShake'},
                                  {"event_name": "座椅状态恢复2",
                                   "event_pattern": r'OnSeat setSeat\w* success'}
                                  ]
        return events_sequential_list,2
    def front_exist(self):
        """座椅通风时顺序判定条件：seek,5D指令,自然播放，OnSeat recoverShake"""
        events_sequential_list = [{"event_name": "跳转进度条到 00:02:55",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:02:\d{2}'},
                                  {"event_name": "座椅通风开启，强度3",
                                   "event_pattern": r'onSeatShake: ts = 00:03:03, action = 11, strength = 3'},
                                  {"event_name": "开始自然播放15s",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "座椅状态恢复1", "event_pattern": r':OnSeat recoverShake'},
                                  {"event_name": "座椅通风强度用户状态恢复",
                                   "event_pattern": r'OnSeat setSeat\w* success'},
                                  {"event_name": "开始自然播放15s",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'}
                                  ]
        return events_sequential_list,3
    def back_exist_5DSDK(self,expect=False):
        """座椅通风区间判定条件：在OnSeat setSeatVentilationLevel success 到日志结束之后有无 5D-SDK下发"""
        events_exist_list = [
            {"start_pattern": r'OnSeat setSeat\w* success',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp|ts = 00:00:00',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list

    def back_exist_time(self, expect=False):
        """座椅通风区间判定条件：在全部日志中有无 GetCurrentTimeStamp timestamp : 183\d{3}下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern":r'GetCurrentTimeStamp timestamp : 183\d{3}',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list
    def back_exist_5D(self,expect=False):
        """座椅通风区间判定条件：在全部日志中有无 onSeatShake: ts = 00:03:03, action = 11, strength = 3 到日志结束之后有无 5D-SDK下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern":'onSeatShake: ts = 00:03:03, action = 11, strength = 3',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list
class SeatMove:
    def start_action_not(self):

        do_mainpage.enter_film("哥斯拉大战金刚")
        time.sleep(10)
        do_playpage.seek_to_target("00:13:15")
        time.sleep(10)


    def back_exist_time(self, expect=False):
        events_exist_list = [
            {"start_pattern": r'pause',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp : 812\d{3}',
             "end_pattern": 'END_OF_LOG',
             "expect": expect}]
        return events_exist_list
    def back_exist_5D_recover(self,expect=False):
        events_exist_list = [
            {"start_pattern": r'pause',
             "start_index": -1,
             "event_pattern": r'onSeatMove: ts = 00:13:32, action = 1, duration = 1000',
             "end_pattern": 'END_OF_LOG',
             "expect": expect}
        ]
        return events_exist_list
class Conditioner:
    """
    空调
   空调：哥斯拉大战金刚  00:00:54~00:01:29
   5D后排：onConditioner: ts = 00:00:48, density = 3, mode = 0, direction = 0
   5D前排：onConditioner: ts = 00:00:52, density = 3, mode = 0, direction = 0
    后排屏提前6S下发 前排根据风量提前 1,2,3秒下发
    """

    def start_action(self):
        """空调下发时操作：打开哥斯拉大战金刚 seek到00:42持续播放20s"""
        do_mainpage.enter_film("哥斯拉大战金刚")
        time.sleep(8)
        do_playpage.seek_to_target("00:00:42")
        time.sleep(20)

    def start_action_not(self):
        """空调下发前操作：打开哥斯拉大战金刚 seek到00:36持续播放10s"""
        do_mainpage.enter_film("哥斯拉大战金刚")
        time.sleep(8)
        do_playpage.seek_to_target("00:00:36")
        time.sleep(10)

    def front_exist_not(self):
        """空调下发前顺序判定条件：seek,自然播放，空调三个恢复"""
        events_sequential_list = [{"event_name": "暂停", "event_pattern": r':pause|OnSeat recoverShake'},
                                  {"event_name": "跳转进度条到 00:00:36",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:\d{2}:\d{2}'},
                                  {"event_name": "开始自然播放10s",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "空调温度恢复", "event_pattern": r'recoverTemperature'},
                                  {"event_name": "空调风量恢复", "event_pattern": r'recoverWindDensity'},
                                  {"event_name": "空调风向恢复", "event_pattern": r'recoverWindDirection'},

                                  ]
        return events_sequential_list,3

    def front_exist(self):
        """空调下发时顺序判定条件：seek,5D指令,自然播放，空调三个恢复"""
        if device_type == "A1Back":
            ins_5D=r'onConditioner: ts = 00:00:48, density = 3, mode = 0, direction = 0'
        else:
            ins_5D=r'onConditioner: ts = 00:00:52, density = 3, mode = 0, direction = 0'

        events_sequential_list = [{"event_name": "跳转进度条到 00:00:45",
                               "event_pattern": r'onGetCurrentTimeStamp seek : 00:00:\d{2} -> 00:00:\d{2}'},
                              {"event_name": "空调52秒预下发",
                               "event_pattern": ins_5D},
                              {"event_name": "空调54秒正式下发",
                               "event_pattern": r'onConditioner: ts = 00:00:54, density = 0, mode = 0, direction = 2'},
                              {"event_name": "开始自然播放10s",
                               "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                              {"event_name": "空调温度恢复", "event_pattern": r'recoverTemperature'},
                              {"event_name": "空调风量恢复","event_pattern": r'recoverWindDensity'},
                              {"event_name": "空调风向恢复","event_pattern": r'recoverWindDirection'},

                              ]

        return events_sequential_list,4

    def back_exist_5DSDK(self, expect=False):
        """座椅通风区间判定条件：在recoverTemperature日志结束之后有无 5D-SDK下发"""
        events_exist_list = [
            {"start_pattern": r'OnSeat setSeat\w* success',
             "start_index": -1,
             "event_pattern": r'5D-SDK',
             "end_pattern": 'END_OF_LOG',
             "expect": expect}
        ]
        return events_exist_list

    def back_exist_time(self, expect=False):
        """空调区间判定条件：在全部日志中有无 GetCurrentTimeStamp timestamp : 48\d{3}后排 52前排下发"""
        if device_type == "A1Back":
            time_5D=r'GetCurrentTimeStamp timestamp : 48\d{3}'
        else:
            time_5D=r'GetCurrentTimeStamp timestamp : 52\d{3}'

        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": time_5D,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list

    def back_exist_5D(self, expect=False):
        """空调区间判定条件：在全部日志中有无 onConditioner: ts = 00:00:48后排/52前排, density = 3, mode = 0, direction = 0下发"""
        if device_type == "A1Back":
            ins_5D=r'onConditioner: ts = 00:00:48, density = 3, mode = 0, direction = 0'
        else:
            ins_5D=r'onConditioner: ts = 00:00:52, density = 3, mode = 0, direction = 0'

        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": ins_5D,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]

        return events_exist_list

    def back_exist_time_recover(self, expect=False):
        """空调区间判定条件：在全部日志中有无 GetCurrentTimeStamp timestamp : 644\d{3}下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp : 652\d{3}',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list
    def back_exist_5D_recover(self,expect=False):
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": r'onConditioner: ts = 00:10:52, density = 2, mode = 0, direction = 0',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list
class ShowColor:
    """氛围灯"""
    def start_action(self):
        """氛围灯有指令时操作：打开哥斯拉大战金刚 seek到4:05持续播放15s"""
        do_mainpage.enter_film("哥斯拉大战金刚")
        time.sleep(8)
        do_playpage.seek_to_target("00:04:08")
        time.sleep(10)

    def start_action_not(self):
        """氛围灯有指令时操作：打开哥斯拉大战金刚 seek到3:58持续播放10s"""
        do_mainpage.enter_film("哥斯拉大战金刚")
        time.sleep(8)
        do_playpage.seek_to_target("00:03:58")
        time.sleep(10)

    def front_exist_not(self):
        """氛围灯前顺序判定条件：seek,自然播放，OnSeat recoverShake"""
        events_sequential_list =  [{"event_name": "跳转进度条到 00:03:58",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:03:\d{2}'},
                                  {"event_name": "开始自然播放15s",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d{6}'},
                                  {"event_name": "暂停", "event_pattern": r'close|pause'},
                                  {"event_name": "状态恢复","event_pattern": r'recoverIntensity'}
                                  ]
        return events_sequential_list,3

    def front_exist(self):
        """氛围灯时顺序判定条件：seek,追溯律动,自然播放，5D指令1234,pause"""
        events_sequential_list = [{"event_name": "跳转进度条到 00:04:05",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:00:\d{2} -> 00:\d{2}:\d{2}'},
                                  {"event_name": "氛围灯向上追溯一条",
                                   "event_pattern": r'onShowColor ts: 00:00:00, type: 3, brightness: 3, color: #2D9600'},
                                  {"event_name": "开始自然播放15s",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d{6}'},
                                  {"event_name": "音乐律动",
                                   "event_pattern": r'onShowColor ts: 00:04:13, type: 6, brightness: 3, color: #797A75'},
                                  {"event_name": "暂停", "event_pattern": r':pause|:close'},
                                  {"event_name": "暂停", "event_pattern": r':recover'}
                                  ]
        return events_sequential_list,4

    def back_exist_5DSDK(self, expect=False):
        """氛围灯时区间判定条件：在:recover到日志结束之后有无 5D-SDK下发"""
        events_exist_list = [
            {"start_pattern": r'OnSeat setSeat\w* success',
             "start_index": -1,
             "event_pattern": r'5D-SDK',
             "end_pattern": 'END_OF_LOG',
             "expect": expect}
        ]
        return events_exist_list


    def back_exist_time(self, expect=False):
        """氛围灯区间判定条件：在全部日志中有无 GetCurrentTimeStamp timestamp : 249\d{3}下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp : 249\d{3}',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list
    def back_exist_5D(self,expect=False):
        """氛围灯区间判定条件：在全部日志中有无 ts: 00:04:11, type: 6, brightness: 2, color: #DFB0B1下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": r'onShowColor ts: 00:04:09, type: 3, brightness: 3, color: #2D9601',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect":expect}
        ]
        return events_exist_list
    def back_exist_time_recover(self, expect=False):
        """氛围灯区间判定条件：在全部日志中有无 GetCurrentTimeStamp timestamp : 251\d{3}下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp : 251\d{3}',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list
    def back_exist_5D_recover(self,expect=False):
        """氛围灯区间判定条件：在全部日志中有无 ts: 00:04:11, type: 6, brightness: 2, color: #DFB0B1下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": r'ts: 00:04:11, type: 6, brightness: 2, color: #DFB0B1',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect":expect}
        ]
        return events_exist_list
class Fragrance:
    """香氛"""

    def start_action(self):
        """氛围灯有指令时操作：打开寻梦环游记 seek到44:45持续播放25s"""
        do_mainpage.enter_film("寻梦环游记")
        time.sleep(8)
        if device_type == "A1Back":
            do_playpage.seek_to_target("00:44:45")
            time.sleep(10)
        else:
            do_playpage.seek_to_target("00:45:00")
            time.sleep(10)



    def start_action_not(self):
        """氛围灯有指令时操作：打开寻梦环游记 seek到44:40持续播放10s"""
        do_mainpage.enter_film("寻梦环游记")
        time.sleep(8)
        if device_type == "A1Back":
            do_playpage.seek_to_target("00:44:40")
        else:
            do_playpage.seek_to_target("00:44:55")
        time.sleep(10)

    def front_exist_not(self):
        """香氛前顺序判定条件：seek,自然播放，recoverIntensity"""
        events_sequential_list = [{"event_name": "开始自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : [0-9]\d{3}'},
                                  {"event_name": "暂停",
                                   "event_pattern": r'pause|OnSeat recoverShake'},
                                  {"event_name": "seek操作1",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:\d{2}:\d{2}'},
                                  {"event_name": "开始自然播放14s",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "暂停",
                                   "event_pattern": r'pause|OnSeat recoverShake'},
                                  ]
        return events_sequential_list, 3

    def front_exist(self):
        """香氛时顺序判定条件：seek,自然播放，5D指令,pause,recoverIntensity"""
        if device_type == "A1Back":
            ins_5D=r'OnFragrance, ts: 2691000, density : THIN - 2, type : 0'
        else:
            ins_5D=r'OnFragrance, ts: 2706000, density : THIN - 2, type : 0'

        events_sequential_list = [{"event_name": "跳转进度条到 00:44:56",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : 00:\d{2}:\d{2} -> 00:\d{2}:\d{2}'},
                                  {"event_name": "开始自然播放14s",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "寻梦环游记 00:45:06 淡 赫尔辛基的雪",
                                   "event_pattern": ins_5D},
                                  {"event_name": "氛围灯恢复",
                                   "event_pattern": r'recoverIntensity|recover'},
                                  ]
        return events_sequential_list, 4

    def back_exist_5DSDK(self, expect=False):
        """氛围灯时区间判定条件：在:recover到日志结束之后有无 5D-SDK下发"""
        events_exist_list = [
            {"start_pattern": r'OnSeat setSeat\w* success',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp|ts = 00:00:00',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list

    def back_exist_time(self, expect=False):
        """氛围灯区间判定条件：在全部日志中有无 GetCurrentTimeStamp timestamp : 2691下发"""
        if device_type == "A1Back":
            time_5D=r'GetCurrentTimeStamp timestamp : 2691\d{3}'
        else:
            time_5D=r'GetCurrentTimeStamp timestamp : 2706\d{3}'
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": time_5D,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list

    def back_exist_time_recover(self, expect=False):
        """香氛区间判定条件：在全部日志中有无 timestamp : 后排4313前排 4328下发"""
        if device_type == "A1Back":
            timestamp=r'GetCurrentTimeStamp timestamp : 4313\d{3}'
        else:
            timestamp=r'GetCurrentTimeStamp timestamp : 2177\d{3}'
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": timestamp,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list
    def back_exist_5D(self,expect=False):
        """香氛区间判定条件：在全部日志中有无 OnFragrance, ts: 4313000/4328000, density : MIDDLE - 3, type : 0下发"""
        if device_type == "A1Back":
            car_5d=r'OnFragrance, ts: 4313000, density : MIDDLE - 3, type : 0'
        else:
            car_5d=r'OnFragrance, ts: 4328000, density : MIDDLE - 3, type : 0'
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": car_5d,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect":expect}
        ]
        return events_exist_list
    def back_exist_5D_recover(self,expect=False):
        """香氛区间判定条件：在全部日志中有无 OnFragrance, ts: 4313000/4328000, density : MIDDLE - 3, type : 0下发"""
        if device_type == "A1Back":
            car_5d=r'OnFragrance, ts: 4313000, density : MIDDLE - 3, type : 0'
        else:
            car_5d=r'OnFragrance, ts: 2177000, density : THIN - 2, type : 0'
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": car_5d,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect":expect}
        ]
        return events_exist_list
class RecoverCheck:

    def __init__(self,car_type):
        self.Fragance_advance_time = 0
        self.SeatHeating_advance_time = 0
        self.Conditioner_advance_time=0
        if device_type == "A1Back":
            self.Fragance_advance_time = 15
            self.SeatHeating_advance_time = 10
            self.Conditioner_advance_time=6
        self.all_list = {
            "座椅律动": {
                "seek1": r"00:00:\d{2} -> 00:03:\d{2}",
                "seek2": r"00:03:\d{2} -> 00:03:\d{2}",
                "seek_all": r"00:(00|03):\d{2} -> 00:03:\d{2}",
                "time_front": str(208-5)+r"\d{3}",
                "time_5D": str(208)+r"\d{3}",
                "time_5D1": str(208) + r"1\d{2}",
                "command": r'onSeatShake: ts = 00:03:28, action = 5, strength = 3'},
            "原子化振动": {
                "seek1": r"00:00:\d{2} -> 00:06:\d{2}",
                "seek2": r"00:06:\d{2} -> 00:06:\d{2}",
                "seek_all": r"00:(00|06):\d{2} -> 00:06:\d{2}",
                "time_front": str(374-5)+r"\d{3}",
                "time_5D": str(374)+r"\d{3}",
                "time_5D1": str(374) + r"1\d{2}",
                "command": r'onSeatShake: ts = 00:06:14, action = 5, strength = 1002'},
            "座椅按摩": {
                "seek1": r"00:00:\d{2} -> 00:58:\d{2}",
                "seek2": r"00:58:\d{2} -> 00:58:\d{2}",
                "seek_all": r"00:(00|58):\d{2} -> 00:58:\d{2}",
                "time_front": str(3495-4)+r"\d{3}",
                "time_5D": str(3495)+r"\d{3}",
                "time_5D1": str(3495) + r"1\d{2}",
                "command": r'onSeatShake: ts = 00:58:15, action = 13, strength = 3'},
            "座椅加热": {
                "seek1": r"00:00:\d{2} -> 00:10:\d{2}",
                "seek2": r"00:10:\d{2} -> 00:10:\d{2}",
                "seek_all": r"00:(00|10):\d{2} -> 00:10:\d{2}",
                "time_front": str(634-self.SeatHeating_advance_time-5)+r"\d{3}",
                "time_5D": str(634-self.SeatHeating_advance_time)+r"\d{3}",
                "time_5D1": str(634 - self.SeatHeating_advance_time) + r"1\d{2}",
                "command": r'onSeatShake: ts = 00:10:{}, action = 7, strength = 3'.format(
                    34 - self.SeatHeating_advance_time)},
            "座椅移动": {
                "seek1": r"00:00:\d{2} -> 00:13:\d{2}",
                "seek2": r"00:13:\d{2} -> 00:13:\d{2}",
                "seek_all":r"00:(00|13):\d{2} -> 00:13:\d{2}",
                "time_front": str(812 - 5) + r"\d{3}",
                "time_5D": str(812) + r"\d{3}",
                "time_5D1": str(812) + r"1\d{2}",
                "command": r'onSeatMove: ts = 00:13:32, action = 1, duration = 1000'},
            "空调": {
                "seek1": r"00:00:\d{2} -> 00:10:\d{2}",
                "seek2": r"00:10:\d{2} -> 00:10:\d{2}",
                "seek_all": r"00:(00|10):\d{2} -> 00:10:\d{2}",
                 "time_front": str(652-self.Conditioner_advance_time-5)+r"\d{3}",
                "time_5D": str(652-self.Conditioner_advance_time)+r"\d{3}",
                "time_5D1": str(650 - self.Conditioner_advance_time) + r"d{3}",
                "command": r"""ts = 00:10:{}, density = [0-9], mode = [0-9], direction = [0-9]""".format(
                    50 - self.Conditioner_advance_time)},
            "氛围灯": {
                "seek1": r"00:00:\d{2} -> 00:(03|04):\d{2}",
                "seek2": r"00:(03|04):\d{2} -> 00:(03|04):\d{2}",
                "seek_all": r"00:(00|03|04):\d{2} -> 00:(03|04):\d{2}",
                "time_front": str(251 - 5) + r"\d{3}",
                "time_5D": str(251) + r"\d{3}",
                "time_5D1": str(251) + r"1\d{2}",
                "command": r'onShowColor ts: 00:04:11, type: 6, brightness: 2, color: #DFB0B1'},
            "香氛": {
                "seek1": r"00:00:\d{2} -> 00:(36|35):\d{2}",
                "seek2": r"00:(36|35):\d{2} -> 00:(36|35):\d{2}",
                "seek_all": r"00:(00|35|36):\d{2} -> 00:(35|36):\d{2}",
                 "time_front": str(2177-self.Fragance_advance_time-5)+r"\d{3}",
                "time_5D": str(2177-self.Fragance_advance_time)+r"\d{3}",
                "time_5D1": str(2177 - self.Fragance_advance_time) + r"1\d{2}",
                "command": r'OnFragrance, ts: {}, density : THIN - 2, type : 0'.format(2177000 - self.Fragance_advance_time*1000)},
        }
        self.seek1 = 'onGetCurrentTimeStamp seek : ' + self.all_list[car_type]["seek1"]
        self.seek2 = 'onGetCurrentTimeStamp seek : ' + self.all_list[car_type]["seek2"]
        self.seek_all = 'onGetCurrentTimeStamp seek : ' + self.all_list[car_type]["seek_all"]
        self.time_5D = "GetCurrentTimeStamp timestamp : " + self.all_list[car_type]["time_5D"]
        self.time_5D1 = "GetCurrentTimeStamp timestamp : " + self.all_list[car_type]["time_5D1"]
        self.time_front = "GetCurrentTimeStamp timestamp : " + self.all_list[car_type]["time_front"]
        self.command =self.all_list[car_type]["command"]
    def seek_back(self):
        events_sequential_list = [
            {"event_name": "00前置seek下发追溯检测:首次seek操作",
             "event_pattern": 'onGetCurrentTimeStamp seek : 00:'},
            {"event_name": "00前置seek下发追溯检测:5D律动灯光追溯1",
             "event_pattern": r'onShowColor ts: 00:00:00|onSeatShake: ts = 00:00:00'},
            {"event_name": "00前置seek下发追溯检测:5D律动灯光追溯2",
             "event_pattern": r'onShowColor ts: 00:00:00|onSeatShake: ts = 00:00:00'},
            {"event_name": "00前置seek下发追溯检测:resume",
             "event_pattern": r'resume'},
            {"event_name": "00前置seek下发追溯检测:追溯seek操作",
             "event_pattern": 'onGetCurrentTimeStamp seek : '}
        ]
        return events_sequential_list, 5

    def pause_seek(self):

        events_sequential_list = [{"event_name": "01顺序中断恢复检索指令下发检测:视频开头打开自然播放10S内",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : [0-9]\d{3}'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:暂停",
                                   "event_pattern": r'pause|OnSeat recoverShake'},
                                  # {"event_name": "01顺序中断恢复检索指令下发检测:第一次暂停时触发seek操作",
                                  #  "event_pattern": 'onGetCurrentTimeStamp seek :'},
                                  # {"event_name": "01顺序中断恢复检索指令下发检测:第二次手动seek操作",
                                  #  "event_pattern": self.seek_all},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:暂停时seek",
                                    "event_pattern": r'pause|OnSeat recoverShake'},
                                  # {"event_name": "01顺序中断恢复检索指令下发检测:操作结束前自然播放",
                                  #  "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'}
                                  ]
        return events_sequential_list,5
    def play_seek(self):
        events_sequential_list = [{"event_name": "01顺序中断恢复检索指令下发检测:视频开头打开自然播放10S内",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : [0-9]\d{3}'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:检测播放时seek中断操作",
                                   "event_pattern": r'pause|OnSeat recoverShake'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:第一次手动seek操作",
                                   "event_pattern": self.seek_all},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:操作结束前自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  ]
        return events_sequential_list, 4
    def pause_play(self):
        events_sequential_list = [{"event_name": "01顺序中断恢复检索指令下发检测:视频开头打开自然播放10S内",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : [0-9]\d{3}'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:检测播放时暂停中断操作",
                                   "event_pattern": r'pause|OnSeat recoverShake'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:暂停后恢复播放引发的seek操作",
                                   "event_pattern": 'onGetCurrentTimeStamp seek : '},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:操作结束前自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  ]
        return events_sequential_list,4
    def card_come(self):
        events_sequential_list = [{"event_name": "01顺序中断恢复检索指令下发检测:视频开头打开自然播放10S内",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : [0-9]\d{3}'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:检测播放时seek引发的中断操作",
                                   "event_pattern": r'pause|OnSeat recoverShake'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:第一次手动seek操作",
                                   "event_pattern": 'onGetCurrentTimeStamp seek : '},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:退出卡片前视频自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:检测播放时退出应用引发的中断操作",
                                   "event_pattern": r'pause|OnSeat recoverShake'},
                                  # {"event_name": "01顺序中断恢复检索指令下发检测:第二次从卡片进入引发的seek操作",
                                  #  "event_pattern": self.seek_all},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:操作结束前自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  ]
        return events_sequential_list, 7
    def jike_come(self):

        events_sequential_list =   [{"event_name": "01顺序中断恢复检索指令下发检测:视频开头打开自然播放10S内",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : [0-9]\d{3}'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:检测播放时seek引发的中断操作",
                                   "event_pattern": r'pause|OnSeat recoverShake'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:第一次手动seek操作",
                                   "event_pattern": 'onGetCurrentTimeStamp seek : '},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:退出卡片前视频自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:检测播放时退出应用引发的中断操作",
                                   "event_pattern": r'pause|OnSeat recoverShake'},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:第二次从影院进入引发的seek操作",
                                   "event_pattern": self.seek_all},
                                  {"event_name": "01顺序中断恢复检索指令下发检测:操作结束前自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  ]
        return events_sequential_list, 7
    def back_exist_time(self, expect=False):
        if expect==False:
            time_5d=self.time_5D1
        else:
            time_5d = self.time_5D
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern":time_5d,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list
    def back_exist_time_front(self, expect=False):
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": self.time_front,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list
    def back_exist_5D(self, expect=False):
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern":self.command,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list
class Check:

    def __init__(self,car_type):
        self.Fragance_advance_time = 0
        self.SeatHeating_advance_time = 0
        self.Conditioner_advance_time=0
        self.car_type = car_type
        if device_type == "A1Back":
            self.Fragance_advance_time = 15
            self.SeatHeating_advance_time = 10
            self.Conditioner_advance_time=6
        self.all_list = {
            "座椅律动": {
                "seek1": r"00:00:\d{2} -> 00:03:\d{2}",
                "seek2": r"00:03:\d{2} -> 00:03:\d{2}",
                "seek_all": r"00:(00|03):\d{2} -> 00:03:\d{2}",
                "time_5D":208,
                "command": r'onSeatShake: ts = 00:03:28, action = 5, strength = 3'},
            "原子化振动":{
                "seek1": r"00:00:\d{2} -> 00:06:\d{2}",
                "seek2": r"00:06:\d{2} -> 00:06:\d{2}",
                "seek_all": r"00:(00|06):\d{2} -> 00:06:\d{2}",
                "time_5D":3741,
                "command": r'onSeatShake: ts = 00:03:28, action = 5, strength = 3'},
            "座椅按摩":{
                "seek1": r"00:00:\d{2} -> 00:(57|58):\d{2}",
                "seek2": r"00:(57|58):\d{2} -> 00:(57|58):\d{2}",
                "seek_all": r"00:(57|58):\d{2} -> 00:(57|58):\d{2}",
                "time_5D":3495,
                "command": r'onSeatShake: ts = 00:58:15, action = 13, strength = 3'},
            "座椅加热": {
                "seek1": r"00:00:\d{2} -> 00:10:\d{2}",
                "seek2": r"00:10:\d{2} -> 00:10:\d{2}",
                "seek_all": r"00:(00|10):\d{2} -> 00:(00|10):\d{2}",
                "time_5D":  634 - self.SeatHeating_advance_time,
                "command": r'onSeatShake: ts = 00:10:{}, action = 7, strength = 3'.format(
                    34 - self.SeatHeating_advance_time)},
            "座椅移动": {
                "seek1": r"00:00:\d{2} -> 00:13:\d{2}",
                "seek2": r"00:13:\d{2} -> 00:13:\d{2}",
                "seek_all": r"00:(00|13):\d{2} -> 00:13:\d{2}",
                "time_5D":812,
                "command": r'onSeatMove: ts = 00:13:32, action = 1, duration = 1000'},
            "座椅通风": {
                "seek1": r"00:00:\d{2} -> 00:02:\d{2}",
                "seek2": r"00:02:\d{2} -> 00:02:\d{2}",
                "seek_all": r"00:(00|02):\d{2} -> 00:(00|02):\d{2}",
                "time_5D": 183,
                "command": r'onSeatShake: ts = 00:03:03, action = 11, strength = 3'},
            "空调": {
                "seek1": r"00:00:\d{2} -> 00:10:\d{2}",
                "seek2": r"00:10:\d{2} -> 00:10:\d{2}",
                "seek_all": r"00:10:\d{2} -> 00:10:\d{2}",
                "time_5D": 652 - self.Conditioner_advance_time,
                "command": r"onConditioner: ts = 00:10:{}, density = [1-9], mode = [1-9], direction = [1-9]".format(
                    52 - self.Conditioner_advance_time)},
            "氛围灯": {
                "seek1": r"00:00:\d{2} -> 00:(03|04):\d{2}",
                "seek2": r"00:(03|04):\d{2} -> 00:(03|04):\d{2}",
                "seek_all": r"00:(03|04):\d{2} -> 00:(03|04):\d{2}",
                "time_5D": 251,
                "command": r'onShowColor ts: 00:04:11, type: 6, brightness: 2, color: #DFB0B1'},
            "香氛": {
                "seek1": r"00:00:\d{2} -> 00:(44|45):\d{2}",
                "seek2": r"00:(44|45):\d{2} -> 00:(44|45):\d{2}",
                "seek_all": r"00:(00|44|45):\d{2} -> 00:(44|45):\d{2}",
                "time_5D": str(2706 - self.Fragance_advance_time),
                "command": r'OnFragrance, ts: {}, density : THIN - 2, type : 0'.format(2706000 - self.Fragance_advance_time*1000)},
        }
        self.seek1 = 'onGetCurrentTimeStamp seek : ' + self.all_list[car_type]["seek1"]
        self.seek2 = 'onGetCurrentTimeStamp seek : ' + self.all_list[car_type]["seek2"]
        self.seek_all = 'onGetCurrentTimeStamp seek : ' + self.all_list[car_type]["seek_all"]
        self.time_5D =r"GetCurrentTimeStamp timestamp : "+str(self.all_list[car_type]["time_5D"])+r"\d{3}"
        self.time_5D1 = r"GetCurrentTimeStamp timestamp : " + str(self.all_list[car_type]["time_5D"]) + r"1\d{2}"
        self.command =self.all_list[car_type]["command"]
    def seek_back(self):
        events_sequential_list = [
                                  {"event_name": "00前置seek下发追溯检测:首次seek操作",
                                   "event_pattern": 'onGetCurrentTimeStamp seek : 00:'},
                                  {"event_name": "00前置seek下发追溯检测:5D律动灯光追溯1",
                                   "event_pattern": r'onShowColor ts: 00:00:00|onSeatShake: ts = 00:00:00'},
                                  {"event_name": "00前置seek下发追溯检测:5D律动灯光追溯2",
                                   "event_pattern": r'onShowColor ts: 00:00:00|onSeatShake: ts = 00:00:00'},
                                {"event_name": "00前置seek下发追溯检测:resume",
                                 "event_pattern": r'resume'},
                                  {"event_name": "00前置seek下发追溯检测:追溯seek操作",
                                   "event_pattern": 'onGetCurrentTimeStamp seek : '}
                                  ]
        return events_sequential_list, 5
    def front_exist_not(self):
        """5D指令下发前顺序判定条件：seek,自然播放,OnSeat recoverShake"""
        if self.car_type=="空调":
            recover=[{"event_name": "01顺序检索指令下发检测:空调恢复", "event_pattern": r'recoverTemperature'},
                        {"event_name": "01顺序检索指令下发检测:空调恢复", "event_pattern": r'recoverWindDensity'},
                        {"event_name": "01顺序检索指令下发检测:空调恢复", "event_pattern": r'recoverWindDirection'}]
            count=4
        elif self.car_type=="氛围灯":
            recover = [{"event_name": "01顺序检索指令下发检测:氛围灯状态恢复1", "event_pattern": r'recoverIntensity'},
                        {"event_name": "01顺序检索指令下发检测:氛围灯状态恢复2","event_pattern": r'OnSeat setSeat\w* success'}]
            count = 4
        else:
            recover = [{"event_name": "01顺序检索指令下发检测:座椅状态恢复1", "event_pattern": r'OnSeat recoverShake'},
                        {"event_name": "01顺序检索指令下发检测:座椅状态恢复2","event_pattern": r'OnSeat setSeat\w* success'}]
            count = 4
        events_sequential_list = [{"event_name": "01顺序检索指令下发检测:跳转进度条",
                                   "event_pattern": self.seek_all},
                                  {"event_name": "01顺序检索指令下发检测:自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'}
                                  ]
        events_sequential_list.extend(recover)
        return events_sequential_list,count
    def front_exist(self):
        """5D指令下发时顺序判定条件：seek,自然播放,5D指令下发,OnSeat recoverShake"""
        if self.car_type=="空调":
            recover=[{"event_name": "01顺序检索指令下发检测:空调恢复", "event_pattern": r'recoverTemperature'},
                        {"event_name": "01顺序检索指令下发检测:空调恢复", "event_pattern": r'recoverWindDensity'},
                        {"event_name": "01顺序检索指令下发检测:空调恢复", "event_pattern": r'recoverWindDirection'}]
            count=2
        elif self.car_type=="氛围灯":
            recover = [{"event_name": "01顺序检索指令下发检测:氛围灯状态恢复1", "event_pattern": r'recoverIntensity'},
                        {"event_name": "01顺序检索指令下发检测:氛围灯状态恢复2","event_pattern": r'OnSeat setSeat\w* success'}]
            count = 2
        else:
            recover = [{"event_name": "01顺序检索指令下发检测:座椅状态恢复1", "event_pattern": r'OnSeat recoverShake'},
                        {"event_name": "01顺序检索指令下发检测:座椅状态恢复2","event_pattern": r'OnSeat setSeat\w* success'}]
            count = 2
        events_sequential_list = [{"event_name": "01顺序检索指令下发检测:跳转进度条",
                                   "event_pattern": self.seek_all},
                                  {"event_name": "01顺序检索指令下发检测:自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "01顺序检索指令下发检测:5D指令下发",
                                   "event_pattern": self.command}
                                  ]
        events_sequential_list.extend(recover)
        return events_sequential_list,count
    def back_exist_5DSDK(self,expect=False):
        """座椅律动时区间判定条件：在OnSeat setSeatVentilationLevel success 到日志结束之后有无 自然播放GetCurrentTimeStamp下发"""
        events_exist_list = [
            {"start_pattern": r'OnSeat setSeat\w* success',
             "start_index": -1,
             "event_pattern": r'GetCurrentTimeStamp timestamp|ts = 00:00:00',
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}]
        return events_exist_list

    def back_exist_time(self, expect=False):
        """座椅律动时区间判定条件：在全部日志中有无5D时间下发"""
        if expect==False:
            time_5d=self.time_5D1
        else:
            time_5d = self.time_5D
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern": time_5d,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list

    def back_exist_5D(self, expect=False):
        """座椅律动时区间判定条件：在全部日志中有无 5D指令下发"""
        events_exist_list = [
            {"start_pattern": r'START_OF_LOG',
             "start_index": -1,
             "event_pattern":self.command,
             "end_pattern": 'END_OF_LOG',
             "end_index": -1,
             "expect": expect}
        ]
        return events_exist_list


    def start_action(self):
        if self.car_type=="座椅律动":
            SeatRhythm().start_action()
        if self.car_type=="原子化振动":
            SeatAtomizationVibration().start_action()
        if self.car_type=="座椅按摩":
           SeatMassage().start_action()
        if self.car_type=="座椅加热":
            SeatHeating().start_action()
        if self.car_type=="座椅通风":
            SeatVentilation().start_action()
        if self.car_type=="空调":
            Conditioner().start_action()
        if self.car_type=="氛围灯":
            ShowColor().start_action()
        if self.car_type=="香氛":
            Fragrance().start_action()
    def start_action_not(self):
        if self.car_type=="座椅律动":
           SeatRhythm().start_action()
        if self.car_type=="原子化振动":
            SeatAtomizationVibration().start_action_not()
        if self.car_type=="座椅按摩":
           SeatMassage().start_action_not()
        if self.car_type=="座椅加热":
            SeatHeating().start_action_not()
        if self.car_type=="座椅通风":
            SeatVentilation().start_action_not()
        if self.car_type=="空调":
            Conditioner().start_action_not()
        if self.car_type=="氛围灯":
            ShowColor().start_action_not()
        if self.car_type=="香氛":
            Fragrance().start_action_not()
    def seek_close(self):
        events_sequential_list = [
                                    {"event_name": "01顺序检索指令下发检测:自然播放",
                                     "event_pattern": r'GetCurrentTimeStamp timestamp : [0-9]\d{3}'},
                                    {"event_name": "01顺序检索指令下发检测:座椅状态恢复1",
                                     "event_pattern": r'OnSeat recoverShake|pause'},
                                    {"event_name": "01顺序检索指令下发检测:跳转进度条",
                                   "event_pattern": self.seek_all},
                                  {"event_name": "01顺序检索指令下发检测:自然播放",
                                   "event_pattern": r'GetCurrentTimeStamp timestamp : \d+'},
                                  {"event_name": "01顺序检索指令下发检测:5D指令下发",
                                   "event_pattern": self.command},
                                    {"event_name": "01顺序检索指令下发检测:座椅状态恢复1",
                                     "event_pattern": r'OnSeat recoverShake|pause'},
                                  {"event_name": "01顺序检索指令下发检测:跳转进度条",
                                   "event_pattern": r'onGetCurrentTimeStamp seek : \d{2}:\d{2}:\d{2} -> \d{2}:\d{2}:\d{2}'},
                                  ]
        return events_sequential_list, 7









